#
# @lc app=leetcode.cn id=20 lang=python3
#
# [20] 有效的括号
#

# @lc code=start
class Solution:
    def isValid(self, str):
        mapping = {")":"(","]":"[","}":"{"}
        stk = []
        for c in str:
            if c in mapping:
                top_element = stk.pop() if stk else '#'
                if mapping[c] != top_element:
                    return False
            else:
                stk.append(c)
        return not stk
            


# @lc code=end

